//
//  TableViewModel+WebRows.swift
//  CooperSwift
//
//  Created by 计海峰 on 2022/1/17.
//

import Foundation

// 通用 rows 的一些扩展
public extension TableViewModelProtocol {

    //MARK: - web cell
    /// web url cell
    func webUrlRow(_ url: String, color: UIColor? = nil, padding: UIEdgeInsets? = nil, key: String, isTarget: Bool = true) -> TableShowWKWebCellModel {
        /// config
        let webConfig = TableShowBaseControlConfig().then {
            if let bgColor = color {
                $0.bgColor = bgColor
            }
            if let webPadding = padding {
                $0.padding = webPadding
            }
            $0.url = url
        }
        /// webview
        let webCellModel = TableShowWKWebCellModel(webConfig).then {
            $0.addTargetKey(key, isTarget: isTarget)
        }
        return webCellModel
    }
    
    /// web content cell
    func webContentRow(_ content: String, color: UIColor? = nil, padding: UIEdgeInsets? = nil, key: String, isTarget: Bool = true) -> TableShowWKWebCellModel {
        /// config
        let webConfig = TableShowBaseControlConfig().then {
            if let bgColor = color {
                $0.bgColor = bgColor
            }
            if let webPadding = padding {
                $0.padding = webPadding
            }
            $0.text = content.convertToHtmlMeta()
        }
        /// webview
        let webCellModel = TableShowWKWebCellModel(webConfig).then {
            $0.addTargetKey(key, isTarget: isTarget)
        }
        return webCellModel
    }
    
}
